package se.webbzon.boltzmann.editor.list;

import java.util.Collection;
import java.util.Comparator;

import javax.swing.ComboBoxModel;

public class NullableSortedComboBoxModel<T> extends NullableSortedListModel<T> implements ComboBoxModel<T> {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = -157950971907144672L;
	
	// The selected item
	private T selectedItem;
	
	/*============================================================
	Constructors
	============================================================*/

	/** Creates a new nullable sorted list model. **/
	public NullableSortedComboBoxModel(Class<T> clazz) {
		super(clazz);
	}
	
	/** Creates a new nullable sorted list model with a given content. **/
	public NullableSortedComboBoxModel(Class<T> clazz, Collection<T> collection) {
		super(clazz,collection);
	}
	
	/** Creates a new nullable sorted list model. **/
	public NullableSortedComboBoxModel(Class<T> clazz, Comparator<T> comparator) {
		super(clazz,comparator);
	}
	
	/** Creates a new nullable sorted list model with a given content. **/
	public NullableSortedComboBoxModel(	Class<T> clazz, Comparator<T> comparator,
									Collection<T> collection) {
		super(clazz,comparator,collection);
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public T getSelectedItem() {
		return selectedItem;
	}

	@SuppressWarnings("unchecked")
	@Override public void setSelectedItem(Object anItem) {
		if (anItem == null || !containsElement((T) anItem))
			selectedItem = null;
		else
			selectedItem = (T) anItem;
		fireContentsChanged(this,0,getSize()-1);
	}

}
